package org.example.myleet.Utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {

    public static <T> T parse(String input, Class<T> c) {
        ObjectMapper om = new ObjectMapper();
        try {
            return om.readValue(input, c);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static <T> String toJson(T t) {
        ObjectMapper om = new ObjectMapper();
        try {
            return om.writeValueAsString(t);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return null;
        }
    }
}
